using System.Collections.Generic;
using System.Text.RegularExpressions;
using FireStarter.CodeGeneration;
using FireStarter.CodeGeneration.Generator;
using FireStarter.CodeGeneration.Parser;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration.Parser
{
    [TestFixture]
    public class TestCommentExpressionParser
    {
        private static readonly List<IActionParser> _defaultActionParsers = new List<IActionParser>() { new ValueExpressionParser(), new ForEachExpressionParser() };

        [Test]
        public void Test_Parse()
        {
            //---------------Set up test pack-------------------
            string text = "--" + TestUtilsCodeGen.GetRandomString();
            IParser parser = new CommentExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            TemplateExpression templateExpression = parser.Parse(ref text, _defaultActionParsers);
            //---------------Test Result -----------------------
            ParserTestUtils.AssertExpressionIsComment(templateExpression);
            Assert.AreEqual("", text);
        }

        [Test]
        public void Test_IsExpressionMatch()
        {
            //---------------Set up test pack-------------------
            string text = "--" + TestUtilsCodeGen.GetRandomString();
            IActionParser parser = new CommentExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsTrue(isExpressionMatch);
        }

        [Test]
        public void Test_IsExpressionMatch_Fails_IfPatternDoesntMatch()
        {
            //---------------Set up test pack-------------------
            string text = TestUtilsCodeGen.GetRandomString();
            IActionParser parser = new CommentExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsFalse(isExpressionMatch);
        }

        [Test]
        public void Test_IsExpressionMatch_Fails_IfNull()
        {
            //---------------Set up test pack-------------------
            string text = null;
            IActionParser parser = new CommentExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsFalse(isExpressionMatch);
        }

        [Test]
        public void Test_IsExpressionMatch_Fails_IfEmpty()
        {
            //---------------Set up test pack-------------------
            string text = "";
            IActionParser parser = new CommentExpressionParser();
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            bool isExpressionMatch = parser.IsExpressionMatch(text);
            //---------------Test Result -----------------------
            Assert.IsFalse(isExpressionMatch);
        } 
    }
}